<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Tournament extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
    }

    public function add_view() {
        $styles = array(
        );
        $scripts = array(
        );

//        $result = Api::tournaments_add(
//                "test tour", //name
//                "Limit Hold'em", // game
//                "No", //private
//                "Yes", //playerChat
//                "Yes", //observerChat
//                5, //tables
//                9, //seats
//                "Yes", //startFull
//                0, //startMin
//                88, //startCode
//                "2014-04-07 05:30", //startTime
//                50, //minPlayers
//                60, //recurMinutes
//                "Yes", //removeNoShows
//                50, //buyIn
//                0, //entryFee
//                100, //prizeBonus
//                "Yes", //multiplyBonus
//                10 , //chips
//                10 , //turnClock
//                20 , //timeBank
//                5 , //level
//                0 , //rebuyLevels
//                60 , //breakTime
//                6 , //breakLevels
//                "500 character" , //description
//                "" , //blinds
//                "" , //payout
//                "Yes"); //auto

        $keep_data = Value_default::tournamentDefault();

//        var_dump($scripts);
//        var_dump($scripts);
//        var_dump($scripts);
//        var_dump($scripts);
//        var_dump($keep_data);
        $data = array(
            'assets' => base_url() . 'assets',
            'title' => 'Index',
            'user_info' => $this->session->userdata('user_info'),
            'styles' => $styles,
            'scripts' => $scripts,
            'keep_data' => $keep_data,
        );



        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/tournament/add_view', $data);
        $this->load->view('admin/include/footer', $data);
    }

    public function list_view() {
        $styles = array(
        );
        $scripts = array(
        );

        $result = Api::tournaments_list();

        $data = array(
            'assets' => base_url() . 'assets',
            'title' => 'Index',
            'user_info' => $this->session->userdata('user_info'),
            'styles' => $styles,
            'scripts' => $scripts,
            'result' => $result,
        );

        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/tournament/list_view', $data);
        $this->load->view('admin/include/footer', $data);
    }

    public function add() {
        $styles = array(
        );
        $scripts = array(
        );
//        var_dump($styles);
//        var_dump($styles);
//        var_dump($styles);
//        var_dump($styles);
//        var_dump($styles);
//        var_dump($_POST);
//        exit();
        $response = Api::tournaments_add(
                        filter_input(INPUT_POST, 'txtName'), filter_input(INPUT_POST, 'ddlGame'), FormValueConverter::checkBoxValue(filter_input(INPUT_POST, 'ckbPrivate')), FormValueConverter::checkBoxValue(filter_input(INPUT_POST, 'ckbPlayerChat')), FormValueConverter::checkBoxValue(filter_input(INPUT_POST, 'ckbObserverChat')), filter_input(INPUT_POST, 'txtTables'), filter_input(INPUT_POST, 'txtSeats'), FormValueConverter::checkBoxValue(filter_input(INPUT_POST, 'ckbStartFull')), filter_input(INPUT_POST, 'txtStartMin'), filter_input(INPUT_POST, 'txtStartCode'), filter_input(INPUT_POST, 'txtStartTime'), filter_input(INPUT_POST, 'txtMinPlayers'), filter_input(INPUT_POST, 'txtRecurMinutes'), filter_input(INPUT_POST, 'txtRemoveNoShows'), filter_input(INPUT_POST, 'txtBuyIn'), filter_input(INPUT_POST, 'txtEntryFee'), filter_input(INPUT_POST, 'txtPrizeBonus'), filter_input(INPUT_POST, 'rdoMultiplyBonus'), filter_input(INPUT_POST, 'txtChips'), filter_input(INPUT_POST, 'txtTurnClock'), filter_input(INPUT_POST, 'txtTimeBank'), filter_input(INPUT_POST, 'txtLevel'), filter_input(INPUT_POST, 'txtRebuyLevels'), filter_input(INPUT_POST, 'txtBreakTime'), filter_input(INPUT_POST, 'txtBreakLevels'), filter_input(INPUT_POST, 'txtDescription'), filter_input(INPUT_POST, 'txtBlinds'), filter_input(INPUT_POST, 'txtPayout'), FormValueConverter::checkBoxValue(filter_input(INPUT_POST, 'ckbAuto')));

        if ($response->Result === 'Ok') {
            $result = Api::tournaments_list();
            $data = array(
                'assets' => base_url() . 'assets',
                'title' => 'Index',
                'user_info' => $this->session->userdata('user_info'),
                'styles' => $styles,
                'scripts' => $scripts,
                'result' => $result,
                'info_message' => "Tournament Added Successfully.",
            );

            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/tournament/list_view', $data);
            $this->load->view('admin/include/footer', $data);
        } else {
            $error_message = $response->Error;
            if (empty($error_message)) {
                $error_message = "";
            }

            $keep_data = Value_default::tournamentDefault();
            $post_values = $_POST;
            foreach ($post_values as $key => $value) {
                $keep_data[$key] = $post_values[$key];
            }

            $data = array(
                'assets' => base_url() . 'assets',
                'title' => 'Index',
                'user_info' => $this->session->userdata('user_info'),
                'styles' => $styles,
                'scripts' => $scripts,
                'error_message' => $error_message,
                'keep_data' => $keep_data,
            );

            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/tournament/add_view', $data);
            $this->load->view('admin/include/footer', $data);
        }
    }

    public function delete($name) {
        $name = urldecode($name);
        Api::tournaments_delete($name);
        $this->list_view();
    }

    public function online($name) {
        $name = urldecode($name);
        Api::tournaments_online($name);
        $this->list_view();
    }

    public function offline($name) {
        $name = urldecode($name);
        Api::tournaments_offline($name);
        $this->list_view();
    }

}

/* End of file tournament.php */
/* Location: ./application/controllers/admin/tournament.php */